<?php
defined('BASEPATH') OR exit('No direct script access allowed');

require_once APPCOMMON.'core/MY_Controller.php';

// 用户鉴权
class UserOAuth_Controller extends Base_Controller{
	
	public $_user;
	public $uid;
	
	public function __construct(){
		parent::__construct();
	}
	
	// 登录状态校验
	public function islogin(){
		$wx_openid = $this->input->cookie('wx_openid');
		// $wx_openid = 'oCbvcv5X0827p3aVr6T4qj4MAkOg';
		/* if(!$wx_openid){
			$this->show_message('请在微信中打开');
		} */
		$this->load->model('user_model');
		$user = $this->user_model->get_row([
			'where' => [
				'wx_openid' => $wx_openid
			]
		]);
		if(!$user){
			$this->show_message('无效用户', 301, $this->_url['home'].'/passport/');
		}
		$this->uid = $user['uid'];
		$this->_user = $user;
		return $user;
	}
	
}

// 管理后台
class Console_Controller extends Base_Controller{
	
	public $user;
	public $uid;
	
	public function __construct(){
		parent::__construct();
		$this->islogin();
	}
	
	// 登录状态校验
	public function islogin(){
		$this->load->library('session');
		$user = $this->session->userdata('admin');
		if(!$user){
			$this->show_message('无效用户', 301, $this->_url['home'].'/login/');
		}
		$this->uid = $user['id'];
		$this->user = $user;
		$this->smarty_assign([
			'_user' => $user
		]);
		return $user;
	}
	
}